<?php

require_once 'StringKit/CEncoding.php';
require_once 'StringKit/COneBytePerCharString.php';
require_once 'StringKit/CBuiltInEncodings.php';

class CISO_8859_1String extends COneBytePerCharString {
	function IteratorClass() {
		return 'CISO_8859_1Iterator';
	}
	
	function MakeNewFromBuffer($buffer) {
		return new CISO_8859_1String($buffer);
	}
	
	function FastBufferOfEncoding($enc) {
		if ($enc == kISOLatin1)
			return $this->Buffer;
		else
			return null;
	}
}

class CISO_8859_1Iterator extends COneBytePerCharIterator {
	function ByteToChar($x) {
		return ord($x);
	}
}

class CISO_8859_1Encoder extends COneBytePerCharEncoder {
	function AppendString($x) {
		$done = 
		($this->FastAppendIfEncoding($x, kASCII) ||
		 $this->FastAppendIfEncoding($x, kISOLatin1));
		if ($done) return;
		
		if ($this->AllowLoss) {
			$buf = $x->FastBufferOfEncoding(kUTF8);
			if (!is_null($buf) && $this->FastAppendBuffer(utf8_decode($buf)))
				return;
		}
		
		parent::AppendString($x);
	}
	
	function BytesForChar($x) {
		if ($x > 255) return null;
		return chr($x);
	}
}

?>